﻿using Furion.DynamicApiController;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebApi1.Application.Controllers;
public class StreamController : Controller
{


   
    public async Task<IActionResult> getStream()
    {
        
        
        string filePath = "test.txt";
        Response.ContentType = "application/octet-stream";
        var reader = new StreamReader(filePath);
        var buffer = new Memory<char>(new char[5]);
        int writeLength = 0;
        //每次读取5个字符写入到流中
        while ((writeLength = await reader.ReadBlockAsync(buffer)) > 0)
        {
            if (writeLength < buffer.Length)
            {
                buffer = buffer[..writeLength];
            }
            await Response.WriteAsync(buffer.ToString());
            await Task.Delay(100);
        }

        return Ok(Response);
    }
}
